package com.diors.commons.network;

import org.jboss.netty.buffer.ChannelBuffer;

/**
 * 屌丝Buffer类
 * @author	darren.ouyang
 * @data	2013-9-10
 */
public class DiorsBuffer 
{

	ChannelBuffer buffer;
	
	DiorsBuffer (ChannelBuffer buffer)
	{
		this.buffer = buffer;
	}
	
	public void setBuffer (ChannelBuffer buffer)
	{
		this.buffer = buffer;
	}
	
	public ChannelBuffer getBuffer ()
	{
		return buffer;
	}
	
	

	public final byte readByte()
	{
		return buffer.readByte();
	}
	
	public final short readShort()
	{
		return buffer.readShort();
	}
	
	public final int readInt()
	{
		return buffer.readInt();
	}
	
	public final long readLong()
	{
		return buffer.readLong();
	}
	
	public final float readFloat()
	{
		return buffer.readFloat();
	}
	
	public final double readDouble()
	{
		return buffer.readDouble();
	}
	
	public final void readString()
	{
		
		
		/*for(int i = 0 ; i < value.length() ; i++)
		{
			buffer.writeChar(value.charAt(i));
		}
		buffer.writeChar('\000');*/
	}
	
	public final boolean readBoolean()
	{
		return buffer.readByte() == 1;
	}
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * 往流中写入一个byte  长度1位
	 * @param buffer
	 * @param b
	 */
	public final void writeByte(int b)
	{
		buffer.writeByte(b);
	}
	
	/**
	 * 往流中写入一个short  长度2位
	 * @param buffer
	 * @param b
	 */
	public final void writeShort(int value)
	{
		buffer.writeShort(value);
	}
	/**
	 * 往流中写入一个int  长度4位
	 * @param buffer
	 * @param b
	 */
	public final void writeInt(int value)
	{
		buffer.writeInt(value);
	}
	/**
	 * 往流中写入一个long  长度8位
	 * @param buffer
	 * @param b
	 */
	public final void writeLong(long value)
	{
		buffer.writeLong(value);
	}
	
	/**
	 * 往流中写入一个float  长度4位
	 * @param buffer
	 * @param b
	 */
	public final void writeFloat(float value)
	{
		buffer.writeFloat(value);
	}
	
	
	/**
	 * 往流中写入一个double  长度8位
	 * @param buffer
	 * @param b
	 */
	public final void writeDouble(double value)
	{
		buffer.writeDouble(value);
	}
	
	public final void writeString(String value)
	{
		for(int i = 0 ; i < value.length() ; i++)
		{
			buffer.writeChar(value.charAt(i));
		}
		buffer.writeChar('\000');
	}
	
	
	public final void writeBoolean(boolean value)
	{
		buffer.writeByte(value ? 1 : 0);
	}
	
}
